 var $={
    "ajax":({type,url,isAsync=true,data={},success})=>{
         //拼接参数的字符串
          let stringdata ="";
          for(let key in data){
            stringdata+=`${key}=${data[key]}&`;
          }
          //把参数字符串的最后一个&去掉  `name=abc&pwd=1111&`
          stringdata=stringdata.substring(0,stringdata.length-1);
        

        // 1 创建核心对象
        let xmlHttpRequest = null;
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlHttpRequest=new XMLHttpRequest();
            }else
            {// code for IE6, IE5
                xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");   
            }
        // 2 创建连接-------------------------------------------
           if(type==='post'){
            xmlHttpRequest.open(type,url,isAsync,success);
            xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            //3 发送请求
            //注意：send（string）最
            xmlHttpRequest.send(stringdata);
           }else{
               //url？后面的参数 称为 查询字符串
            xmlHttpRequest.open(type,url+"?"+stringdata,isAsync,success);
            xmlHttpRequest.send();
           }
        //4处理响应
        xmlHttpRequest.onreadystatechange=()=>{
            if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200){
                 let data = xmlHttpRequest.responseText;
                 //console.log(data);
                 //调用回调函数，并返回的数据传递为回调函数
                 success(data);
            }else{
                new Error("请求异常");
            }
        }
    }
}